package scau.erps.app;

import org.nutz.ioc.Ioc;
import org.nutz.ioc.impl.NutIoc;
import org.nutz.ioc.loader.json.JsonLoader;

import scau.erps.entity.Sand;
import scau.erps.entity.Staff;
import scau.erps.entity.Store;
import scau.erps.entity.Team;
import scau.erps.service.impl.SandServiceImpl;
import scau.erps.service.impl.StoreServiceImpl;

/**
 * 系统级工厂类、变量等
 * @author DCJ
 *
 */
public class Erps {
	private static Ioc ioc = null;
	private static Team currentTeam = null;
	private static Staff currentStaff = null;
	private static Sand sand = null;
	private static Store store = null;
	static{
		if(ioc == null){
			ioc = new NutIoc(new JsonLoader("ioc.json"));
		}		
	}

	/**
	 * 获得ioc单实例
	 * @return
	 */
	public static Ioc getIocInstance(){
		return ioc;
	}
	/**
	 * 获得当前登录用户
	 * @return
	 */
	public static Team getCurrentTeam() {
		return currentTeam;
	}
	/**
	 * 登陆时注入登陆用户信息
	 * @param currentTeam
	 */
	public static void setCurrentTeam(Team currentTeam) {
		Erps.currentTeam = currentTeam;
	}
	/**
	 * 获得当前登录工作人员
	 * @return
	 */
	public static Staff getCurrentStaff() {
		return currentStaff;
	}
	/**
	 * 登陆时注入工作人员信息
	 * @param currentStaff
	 * 
	 */
	public static void setCurrentStaff(Staff currentStaff) {
		Erps.currentStaff = currentStaff;
	}
	/**
	 * 取得当前用户沙盘数据
	 * @return
	 */
	public static Sand getSand() {
		if (currentTeam !=null & ioc!=null ){
			sand =  ioc.get(SandServiceImpl.class).getSandByTeam(currentTeam.getId());
		}
		return sand;
	}
	/**
	 * 取得当前用户仓库数据
	 * @return
	 */
	public static Store getStore() {
		if (currentTeam !=null & ioc!=null ){
			store =  ioc.get(StoreServiceImpl.class).getStoreByTeamId(currentTeam.getId());
		}
		return store;
	}	
}
